package com.cskaoyan.catmall.service.Impl;

import com.cskaoyan.catmall.dao.AfterSaleDao;
import com.cskaoyan.catmall.model.bo.AfterSaleBo;
import com.cskaoyan.catmall.model.bo.AfterSaleOrderInfoBo;
import com.cskaoyan.catmall.model.vo.AfterSaleVo;
import com.cskaoyan.catmall.model.vo.GoodVo;
import com.cskaoyan.catmall.model.vo.GoodeDetailVo;
import com.cskaoyan.catmall.service.AfterSaleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 逍遥子
 * @Date: 2022/01/07/21:29
 * @Description:
 */
@Service
public class AfterSaleServiceImpl implements AfterSaleService {

    @Autowired
    AfterSaleDao afterSaleDao;

    @Override
    public AfterSaleVo selectAfterSale(AfterSaleBo afterSaleBo) {
        Integer page = afterSaleBo.getPage(); // 第几页
        Integer limit = afterSaleBo.getLimit(); // 一页显示几条数据

        PageHelper.startPage(page, limit);

        List<AfterSaleVo.ListDTO> listDTOS = afterSaleDao.selectAfterSale(afterSaleBo);

        PageInfo<GoodeDetailVo> pageInfo = new PageInfo(listDTOS);

        long total = pageInfo.getTotal(); // 查询数据总条数
        int pages = pageInfo.getPages();  // 计算总共几页数据

        // 封装售后订单信息
       return new AfterSaleVo(total, pages, limit, page, listDTOS);
    }


    /**
     * @description 更新售后订单审核状态
     * @author czx
     * @date 2022-01-07 22:20
     * @param
     * @param ids
     * @return int
     */
    @Override
    public int updateAfterSale(List<Integer> ids, Integer status) {

        // 更新订单状态
        return afterSaleDao.updateAfterSale(ids, status);
    }

    /**
     * @description 更新订单退款信息
     * @author czx
     * @date 2022-01-07 23:25
     * @param
     * @param afterSaleOrderInfoBo
     * @return int
     */
    @Override
    public int updateAfterSaleRefundInfo(AfterSaleOrderInfoBo afterSaleOrderInfoBo) {
        return afterSaleDao.updateAfterSaleRefundInfo(afterSaleOrderInfoBo);

    }

    /**
     * @description 更新订单状态
     * @author czx
     * @date 2022-01-12 16:37
     * @param
     * @param afterSaleOrderInfoBo
     * @return int
     */
    @Override
    public int updateAfterSaleStatus(AfterSaleOrderInfoBo afterSaleOrderInfoBo, Integer status) {
        return afterSaleDao.updateAfterSaleStatus(afterSaleOrderInfoBo, status);
    }
}
